package com.example.toutiao.ui.main.presenter

import com.example.toutiao.http.HttpUtils
import com.example.toutiao.http.ResponseListener
import com.example.toutiao.http.UserApi
import com.example.toutiao.mvp.model.BaseModel
import com.example.toutiao.mvp.presenter.BasePresenter
import com.example.toutiao.ui.main.model.CommonModel
import com.example.toutiao.ui.main.model.MainModel
import com.example.toutiao.ui.main.model.UserInfoModel
import com.example.toutiao.ui.main.view.MainView
import com.example.toutiao.ui.main.view.MineView

class MinePresenter: BasePresenter<MineView>() {
    fun getCommList(type:Int){
        HttpUtils.sendHttp(HttpUtils.createApi(UserApi::class.java).getCommList(type),object :ResponseListener<BaseModel<List<CommonModel>>>{
            override fun onSuccess(data: BaseModel<List<CommonModel>>) {
                if(data!=null&&data.code==200){
                    getBaseView()!!.setData(data.data)
                }
            }
            override fun onFail(err: String) {
                getBaseView()!!.setError(err)
            }

        })
    }

    fun getUserInfo(token:String){
        HttpUtils.sendHttp(HttpUtils.createApi(UserApi::class.java).getUserInfo(token),object :ResponseListener<BaseModel<UserInfoModel>>{
            override fun onSuccess(data: BaseModel<UserInfoModel>) {
                if(data!=null&&data.code==200){
                    getBaseView()!!.updateUserInfo(data.data)
                }
            }
            override fun onFail(err: String) {
                getBaseView()!!.setError(err)
            }

        })
    }
}